package com.yt.base.controller.order;


import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.yt.base.controller.core.BaseController;
import com.yt.base.util.ExcelOpareUtil;
import com.yt.base.util.FileUploadUtil;
import com.yt.base.vo.OGroupOrderProductVo;
import com.yt.core.MsgBean;
import com.yt.core.dao.filter.DynamicSQLFilterImpl;
import com.yt.core.dao.filter.QueryFilter;
import com.yt.order.api.interfaces.*;
import com.yt.order.api.model.*;
import com.yt.order.api.utils.OrderConstants;
import com.yt.util.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/order/groupOrder")
public class GroupOrderController extends BaseController {
	@Autowired
	private GroupOrderService groupOrderService;
	@Autowired
	private InstitutionService institutionService;
	@Autowired
	private GroupOrderProductService groupOrderProductService;
	@Autowired
	private OrderInfoService oOrderInfoService;
	@Autowired
	private ProductService productService;
	@Autowired
	private ReservationService reservationService;
	@Autowired
	private OrderNumberService oOrderNumberService;

	private final Logger logger = LoggerFactory.getLogger(getClass());

	@RequestMapping("/list")
	public ModelAndView list(@RequestParam(value = "groupName", required = false) String groupName, @RequestParam(value = "contactName", required = false) String contactName, HttpServletRequest request) {
		ModelAndView mav = new ModelAndView("order/groupOrder/GroupOrderList");
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter(request.getParameterMap());
		if (StringUtils.isNotEmpty(groupName)) {
			filter.addFilter("Q_groupName_S_LK", groupName.trim());
			mav.addObject("groupName", groupName.trim());
		}
		if (StringUtils.isNotEmpty(contactName)) {
			filter.addFilter("Q_contactName_S_LK", contactName.trim());
			mav.addObject("contactName", contactName.trim());
		}
		filter.setSortField("id", true);
		List<GroupOrder> list = groupOrderService.find(filter);
		int count = groupOrderService.count(filter);
		List<Institution> institutionList = institutionService.getIdAndName(true);
		mav.addObject("list", list);
		mav.addObject("institutionList", institutionList);
		mav.addObject("total", count);
		mav.addObject("start", filter.getPagingBean().getStart());
		mav.addObject("limit", filter.getPagingBean().getPageSize());
		return mav;
	}

	@RequestMapping("/toAdd")
	public ModelAndView toAdd(HttpServletRequest request) {
		ModelAndView mav = new ModelAndView("order/groupOrder/GroupOrderAdd");
		List<Institution> institutions = institutionService.getIdAndName(false);
		mav.addObject("institutionList", institutions);
		return mav;
	}

	@RequestMapping("/toEdit")
	public ModelAndView toEdit(HttpServletRequest request, @RequestParam("id") Long id) {
		ModelAndView mav = new ModelAndView("order/groupOrder/GroupOrderAdd");
		GroupOrder groupOrder = groupOrderService.get(id);
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter("Q_idGroupOrder_L_EQ", groupOrder.getId() + "");
		List<GroupOrderProduct> list = groupOrderProductService.find(filter);
		List<OGroupOrderProductVo> voList = Lists.newArrayList();
		OGroupOrderProductVo vo = null;
		Product product = null;
		Institution institution = null;
		for (GroupOrderProduct obj : list) {
			vo = new OGroupOrderProductVo();
			BeanUtils.copyProperties(obj, vo);
			product = productService.get(obj.getIdProduct());
			if (product != null) {
				vo.setProductName(product.getName());
				institution = institutionService.get(product.getIdInstitution());
				if (institution != null) {
					vo.setIdInstitution(institution.getId());
					vo.setInstitutionName(institution.getName());
					voList.add(vo);
				}
			}
		}
		mav.addObject("selectedProducts", voList);
		List<Institution> institutions = institutionService.getIdAndName(false);
		mav.addObject("institutionList", institutions);
		mav.addObject("bean", groupOrder);
		return mav;
	}

	@RequestMapping("/multiDel")
	@ResponseBody
	public Object multiDel(@RequestParam("ids") String ids) {
		MsgBean msg = new MsgBean();
		String[] idArr = ids.split(",");
		if (ids != null) {
			for (String id : idArr) {
				this.groupOrderService.remove(new Long(id));
			}
		}
		return msg.returnMsg();
	}
	@RequestMapping("/toRemark")
	public ModelAndView toRemark(HttpServletRequest request, @RequestParam("id") Long id) {
		ModelAndView mav = new ModelAndView("order/groupOrder/remark");
		GroupOrder groupOrder = groupOrderService.get(id);
		mav.addObject("groupOrder", groupOrder);
		return mav;
	}

	@RequestMapping("/remark")
	@ResponseBody
	public Object multiDel(@RequestParam("id") Long id, @RequestParam("remark") String remark) {
		MsgBean msg = new MsgBean();
		GroupOrder groupOrder = groupOrderService.get(id);
		groupOrder.setRemark(remark);
		groupOrderService.update(groupOrder);
		return msg.returnMsg();
	}

	@RequestMapping("/showAmount")
	@ResponseBody
	public Object showAmount(@RequestParam("id") Long id) {
		MsgBean msg = new MsgBean();
		Float amount = this.groupOrderService.getGroupOrderTotalAmount(id);
		msg.put("amount", amount != null?amount:0);
		return msg.returnMsg();
	}

	@RequestMapping("/save")
	@ResponseBody
	public Object save(GroupOrder groupOrder,
					   @RequestParam(value = "startTime", required = false) String startDate,
					   @RequestParam(value = "endTime", required = false) String endDate,
					   @RequestParam(value = "selectedProuctIds", required = false) String productIds) {
		MsgBean msg = new MsgBean();
		Date date = DateUtils.parseDate(startDate);
		groupOrder.setStartDate(date != null ? date.getTime() / 1000 : 0);
		date = DateUtils.parseDate(endDate);
		groupOrder.setEndDate(date != null ? date.getTime() / 1000 : 0);
		if (groupOrder.getId() != null) {
			this.groupOrderService.update(groupOrder);
			//先删除，再保存
			QueryFilter filter = new DynamicSQLFilterImpl();
			filter.addFilter("Q_idGroupOrder_L_EQ", groupOrder.getId() + "");
			List<GroupOrderProduct> list = groupOrderProductService.find(filter);
			for (GroupOrderProduct groupOrderProduct : list) {
				groupOrderProductService.remove(groupOrderProduct.getId());
			}
			List<String> productIdList = Splitter.on(",").omitEmptyStrings().splitToList(productIds);
			for (String productId : productIdList) {
				GroupOrderProduct groupOrderProduct = new GroupOrderProduct();
				groupOrderProduct.setIdGroupOrder(groupOrder.getId());
				groupOrderProduct.setIdProduct(Long.parseLong(productId));
				groupOrderProductService.insert(groupOrderProduct);
			}
		} else {
			groupOrder.setCreateTime(System.currentTimeMillis() / 1000);
			this.groupOrderService.insert(groupOrder);
			if (groupOrder.getId() != null && groupOrder.getId() > 0) {
				List<String> productIdList = Splitter.on(",").omitEmptyStrings().splitToList(productIds);
				for (String productId : productIdList) {
					GroupOrderProduct groupOrderProduct = new GroupOrderProduct();
					groupOrderProduct.setIdGroupOrder(groupOrder.getId());
					groupOrderProduct.setIdProduct(Long.parseLong(productId));
					groupOrderProductService.insert(groupOrderProduct);
				}
			}

		}
		return msg.returnMsg();
	}

	@RequestMapping("/get")
	@ResponseBody
	public Object get(@RequestParam("id") Long id) {
		MsgBean msg = new MsgBean();
		GroupOrder groupOrder = this.groupOrderService.get(id);
		msg.put("data", groupOrder);
		return msg.returnMsg();
	}

	/**
	 * 修改订单状态
	 *
	 * @param idArray
	 * @param field
	 * @param status
	 * @return
	 */
	@RequestMapping("/changeStatus")
	@ResponseBody
	public Object changeStatus(@RequestParam("ids") String idArray, @RequestParam("field") String field, @RequestParam("status") String status) {
		MsgBean msg = new MsgBean();
		try {
			List<String> ids = Splitter.on(",").omitEmptyStrings().splitToList(idArray);
			OrderInfo orderInfo = null;
			for (int i = 0; i < ids.size(); i++) {
				orderInfo = oOrderInfoService.get(Long.parseLong(ids.get(i)));
				if ("isChecked".equals(field)) {
					orderInfo.setIsChecked(status);
					logger.info("修改到检", orderInfo.toString(), "OrderInfo");
				} else if ("reportStatus".equals(field)) {
					orderInfo.setReportStatus(status);
					orderInfo.setIsChecked(status);
					logger.info("修改报告状态", orderInfo.toString(), "OrderInfo");
				} else if ("paidToInstitution".equals(field)) {
					orderInfo.setPaidToInstitution(status);
					logger.info("修改付款给商家", orderInfo.toString(), "OrderInfo");
				} else if ("orderState".equals(field)) {
					orderInfo.setOrderStatus(status);
					logger.info("修改订单状态", orderInfo.toString(), "OrderInfo");
				}
				oOrderInfoService.update(orderInfo);
			}
		} catch (Exception ex) {
			logger.error("changeStatusOf");
		}
		return msg.returnMsg();
	}

	@RequestMapping("/uploadExcel")
	@ResponseBody
	public Object uploadExcel(@RequestParam(value = "file", required = false) MultipartFile file, @RequestParam(value = "groupId") Long groupId, HttpServletRequest request) {
		MsgBean msg = new MsgBean();
		try {
			GroupOrder groupOrder = groupOrderService.get(groupId);
			String uploadPath = request.getRealPath("/templets/data/");
			String destName = FileUploadUtil.upload(file, uploadPath);
			System.out.println("上传成功:" + destName);
			List result = uploadFileCompete(uploadPath + "/" + destName, groupOrder);
			boolean resultFlag = (boolean) result.get(0);
			if (resultFlag) {
				msg.setFailure(0, result.get(1).toString());
				return msg.returnMsg();
			} else {
				msg.setFailure(1, result.get(1).toString());
				return msg.returnMsg();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error("导入数据出错，", ex);
		}
		return msg.returnMsg();
	}

	public List uploadFileCompete(String fileToBeRead, GroupOrder qiye) {
		int result = 0;
		StringBuilder sb = new StringBuilder();
		Map<String, Institution> instMap = new HashMap<String, Institution>();
		Map<String, Product> proMap = new HashMap<String, Product>();
		List<OrderInfo> orderList = new ArrayList<OrderInfo>();
		try {
			HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(fileToBeRead));
			HSSFSheet sheet = workbook.getSheetAt(0);
			HSSFRow row = null;
			HSSFCell cell = null;
			int rowNum, cellNum;
			rowNum = sheet.getLastRowNum();
			StringBuilder comments = new StringBuilder();
			OrderInfo detail = null;
			Institution institution = null;
			Product product = null;
			List<Institution> institutionList = null;
			Date orderTime = new Date();
			int born = 0;
			int year = Calendar.getInstance().get(Calendar.YEAR);
			for (int i = 1; i <= rowNum; i++) {
				try {
					row = sheet.getRow(i);
					if (row == null) {// 过滤掉Excel的空行
						continue;
					}
					detail = new OrderInfo();
					//默认值
					detail.setOrderType("团体");
					cell = row.getCell((short) 0); // 姓名
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						detail.setBuyUser(replaceEnter(cell.toString()));
					}
					cell = row.getCell((short) 1); // 体检人
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
//						detail.setTijian(replaceEnter(cell.toString()));
						detail.setEndUser(replaceEnter(cell.toString()));
					}

					cell = row.getCell((short) 2); // 性别
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						detail.setSex(replaceEnter(cell.toString()));
					}
					cell = row.getCell((short) 3); // 年龄
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						try {
							detail.setAge(Double.valueOf(cell.toString().trim().replace("'", "")).intValue());
						} catch (Exception ex) {
							detail.setAge(0);
						}
					} else {
						detail.setAge(0);
					}
					cell = row.getCell((short) 4); // 身份证号
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						detail.setIdCard(replaceEnter(cell.toString().trim()));
						// 如果年龄为0， 根据身份证自动计算年龄
						try {
							if (detail.getAge().longValue() == 0) {
								if (detail.getIdCard().length() == 15) {
									born = 1900 + (new Long(detail.getIdCard().substring(6, 8))).intValue();
								} else if (detail.getIdCard().length() == 18) {
									born = (new Long(detail.getIdCard().substring(6, 10))).intValue();
								}
								detail.setAge(year - born);
							}
						} catch (Exception ex) {
						}
					}

					cell = row.getCell((short) 5); // 商家
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						detail.setInstitutionName(replaceEnter(cell.toString()));
					}

					cell = row.getCell((short) 6); // 产品
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						detail.setProductName(replaceEnter(cell.toString()));
					}
					cell = row.getCell((short) 7); // 销售价
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						detail.setSalePrice(Float.valueOf(replaceEnter(cell.toString())).longValue());
					} else {
						sb.append("第" + (i + 1) + "行：销售价错误;");
					}
					cell = row.getCell((short) 8); //卡号
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						detail.setCardNumber(replaceEnter(cell.toString()));
					}
					cell = row.getCell((short) 9); //密码
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						detail.setCardPassword(replaceEnter(cell.toString()));
					}
					cell = row.getCell((short) 10); //预约信息
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
//						detail.setBespeakInfo(replaceEnter(cell.toString()));
						detail.setBespeaked(replaceEnter(cell.toString()));
					}

					cell = row.getCell((short) 11); //手机号
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						detail.setMobile(replaceEnter(cell.toString()));
					}

					cell = row.getCell((short) 12); //电话
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						detail.setPhone(replaceEnter(cell.toString()));
					}

					cell = row.getCell((short) 13); //地址
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						detail.setAddress(replaceEnter(cell.toString()));
					}
					cell = row.getCell((short) 14); //邮编
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						detail.setPostcode(replaceEnter(cell.toString()));
					}
					cell = row.getCell((short) 15); //报告领取方式
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						detail.setReportType(replaceEnter(cell.toString()));
					}
					cell = row.getCell((short) 16); //有效期开始
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						System.out.println(cell.toString());
						detail.setStartDate(formatDate(replaceEnter(cell.toString())));
					}
					cell = row.getCell((short) 17); //有效期结束
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						System.out.println(cell.toString());
						detail.setEndDate(formatDate(replaceEnter(cell.toString())));
					}
					cell = row.getCell((short) 18); //备注1
					if (cell != null && StringUtils.isNotEmpty(cell.toString())) {
						comments.append(replaceEnter(cell.toString())).append("   ");
					}
					// detail.setStartDate(groupBuying.getStartDate());
					// detail.setEndDate(groupBuying.getEndDate());
					detail.setComment(comments.toString());
					detail.setGroupOrderId(qiye.getId());
					// 设置订单号
//					detail.setOrderNo(OrderNumberManager.nextOrderNumber(OrderNumberManager.OrderFrom.Ekang.getValue(), OrderNumberManager.OrderType.Group.getType()));
					detail.setOrderNo(oOrderNumberService.nextOrderNumber(OrderConstants.OrderFrom.INTERNAL.getValue(), OrderConstants.OrderType.Group.getType()));

//					detail.setOrderNo(orderTime.getTime() + "");
					detail.setOrderTime(orderTime.getTime());
					detail.setOrderStatus(OrderConstants.OrderStatus.NewOrder.getStatusValue());
					detail.setOrderFrom(qiye.getGroupName());
//					detail.setAgentId(qiye.getAgentId());

					detail.setCompany(qiye.getCompanyName());
					detail.setGroupName(qiye.getGroupName());
					// 匹配现有的合作商家
					if (instMap.containsKey(detail.getInstitutionName())) {
						institution = instMap.get(detail.getInstitutionName());
					} else {
						institutionList = institutionService.getInstitutionByName(detail.getInstitutionName());
						if (institutionList != null && !institutionList.isEmpty()) {
							institution = institutionList.get(0);
						} else {
							institution = null;
						}
						if (institution != null) {
							instMap.put(detail.getInstitutionName(), institution);
						}
					}
					if (institution != null) {
						detail.setInstitutionName(institution.getName());
						detail.setIdInstitution(institution.getId());
					} else {
						//detail.setInstitutionName("");
						detail.setIdInstitution(0l);
					}
					// 合作商家不为空时，匹配产品
					if (institution != null) {
						if (proMap.containsKey(institution.getId() + detail.getProductName())) {
							product = proMap.get(institution.getId() + detail.getProductName());
						} else {
							product = productService.getProductByInstutionByName(institution.getId(), detail.getProductName());
							proMap.put(institution.getId() + detail.getProductName(), product);
						}
					} else {
						product = null;
					}
//					detail.setProduct(product);
					if (product != null) {
						detail.setIdProduct(product.getId());
						detail.setProductName(product.getName());

						detail.setProductPrice(product.getPrice());
						detail.setBasePrice(product.getBasePrice());
						if (detail.getSex() != null) {
							if ((product.getName().indexOf("男") != -1 && detail.getSex().indexOf("女") != -1) || (product.getName().indexOf("女") != -1 && detail.getSex().indexOf("男") != -1)) {
								sb.append("第" + (i + 1) + "行：性别与套餐不符;");
							}
						}
					}
					orderList.add(detail);
					comments.delete(0, comments.length());
					result++;
				} catch (Exception ex) {
					//sb.append("第" + (i + 1) + "行：导入失败（" + ex.getMessage().replace("\"", "") + "）;");
					sb.append("第" + (i + 1) + "行：导入失败");
					logger.error(sb.toString());
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		List returnList = new ArrayList();
		if (sb.length() > 0) {
			returnList.add(false);
			returnList.add(sb.toString());
		} else {
			if (orderList.size() < 100) {
				for (OrderInfo order : orderList) {
					oOrderInfoService.insert(order);
					logger.info("批量导入订单", order.toString(), "OrderInfo");
					//TODO:应该没有自动预约
					// 如果合作商家的属性中，自动预约属性为1， 则添加订单的同时自动增加预约记录
//					if (order.getIdProduct() != null && order.getIdInstitution() != null && "1".equals(order.getInstitution().getAutoReserve())) {
//						reservationService.addReservationByOrder(order);
//						order.setBespeaked("1");
//						orderInfoService.save(order);
//						logger.info("自动更新预约状态", order.toString(), "OrderInfo");
//					}
				}
			} else {
				oOrderInfoService.batchSave(orderList);
			}
			returnList.add(true);
			returnList.add(result);
		}
		return returnList;
	}

	@RequestMapping("/exportGroupOrder")
	@ResponseBody
	public void exportGroupOrder(@RequestParam("id") Long groupOrderId, HttpServletResponse response) throws Exception{
		//订单来源	购买人	体检人姓名	体检人性别	体检人年龄	电话	手机
		// 地址	商家名称	套餐名称	卡号	市场价格	成交价格	备注	加项内容	加项价格	订单时间	报告领取方式	已到检	报告已回	是否已预约
		List<String> title = new ArrayList<String>();
		title.add("订单来源");
		title.add("订单号");
		title.add("购买人");
		title.add("使用人姓名");
		title.add("使用人性别");
		title.add("使用人年龄");
		title.add("电话");
		title.add("手机");
		title.add("商家名称");
		title.add("套餐名称");
		title.add("市场价格");
		title.add("成交价格");
		title.add("备注");
		title.add("订单时间");
		title.add("是否已付款给商家");
		title.add("是否到检");
		title.add("报告已回");
		title.add("报告领取方式");
		title.add("预约日期");
		title.add("预约机构");
		List<List> excelList = new ArrayList<List>();
		List<OrderInfo> list = oOrderInfoService.getGroupOrderList(groupOrderId);
		Reservation reservation = null;
		if (list.size() > 0) {
			for (OrderInfo ob : list) {
				if ("-1".equals(ob.getOrderStatus())) {
					continue;
				}
				List<String> strlist = new ArrayList<String>();
				strlist.add(ob.getGroupName());
				strlist.add("_" + ob.getOrderNo());
				strlist.add(ob.getBuyUser());
				strlist.add(ob.getEndUser());
				strlist.add(ob.getSex());
				strlist.add((ob.getAge() != null ? ob.getAge().toString() : ""));
				strlist.add(ob.getPhone());
				strlist.add(ob.getMobile());
				strlist.add(ob.getInstitutionName() != null ? ob.getInstitutionName() : "");
				strlist.add(ob.getProductName() != null ? ob.getProductName() : "");
				strlist.add(ob.getProductPrice() != null ? ob.getProductPrice().toString():"0");
				strlist.add((ob.getSalePrice() != null ? ob.getSalePrice().toString() : "0"));
				strlist.add(ob.getComment());
				strlist.add(DateUtils.formatDate(new Date(ob.getOrderTime()*1000)));
				strlist.add(ob.getPaidToInstitution() == null || "0".equals(ob.getPaidToInstitution()) ? "否" : "是");
				strlist.add(ob.getIsChecked() != null && ob.getIsChecked().equals("1") ? "是" : "否");
				strlist.add(ob.getReportStatus() != null && ob.getReportStatus().equals("1") ? "是" : "否");
				strlist.add(ob.getReportType());
				reservation = reservationService.findValidByOrderId(ob.getOrderNo());
				if(reservation != null) {
					strlist.add(DateUtils.formatDate(new Date(reservation.getReserveDate()*1000)));
					strlist.add(reservation.getInstitutionName());
				}
				excelList.add(strlist);
			}
		}

		response.reset();
		response.setContentType("application/vnd.ms-excel");

		response.setHeader("Content-Disposition", "attachment;Filename=Data(" + DateUtils.formatDateTime(new Date()).replace(" ","").replace("-","").replace(":","") + ").xls");

		ExcelOpareUtil.write(response.getOutputStream(), title, excelList);

	}

	public String replaceEnter(String str) {
		if (str != null) {
			return str.trim().replace("'", "").replace("\n", "").replace("\r", "");
		}
		return null;
	}

	public Long formatDate(String dateStr) {
		try {
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			Date date = format.parse(dateStr);
			return date.getTime()/1000;
		} catch (Exception ex) {
			logger.error("格式化时间出错：", ex);
		}
		return 0l;
	}

}
